package MyUtil;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class ObjectListUtil {
    private ObjectListUtil(){
    }
    public static List<Object[]> getDataList(String sql) throws SQLException {
        ResultSet rs  = DataBaseUtil.produceResultSet(sql);
        List<Object[]> list = new ArrayList<>();
        while(rs.next()){
            Object[] objects = new Object[6];
            objects[0] = rs.getInt(1);
            objects[1] = rs.getString(2);
            objects[2] = rs.getString(3);
            objects[3] = rs.getInt(4);
            objects[4] = rs.getFloat(5);
            objects[5] = rs.getDate(6);
            list.add(objects);
        }
        return  list;
    }
    public static List<Object[]> getDataList(String sql,Object... objects1) throws SQLException {
        ResultSet rs  = DataBaseUtil.prepareResultSet(sql,objects1);
        List<Object[]> list = new ArrayList<>();
        while(rs.next()){
            Object[] objects = new Object[6];
            objects[0] = rs.getInt(1);
            objects[1] = rs.getString(2);
            objects[2] = rs.getString(3);
            objects[3] = rs.getInt(4);
            objects[4] = rs.getFloat(5);
            objects[5] = rs.getDate(6);
            list.add(objects);
        }
        return  list;
    }
    public static List<Object[]> getDataList(ResultSet rs) throws SQLException {
        List<Object[]> list = new ArrayList<>();
        while(rs.next()){
            Object[] objects = new Object[6];
            objects[0] = rs.getInt(1);
            objects[1] = rs.getString(2);
            objects[2] = rs.getString(3);
            objects[3] = rs.getInt(4);
            objects[4] = rs.getFloat(5);
            objects[5] = rs.getDate(6);
            list.add(objects);
        }
        return  list;
    }

    public static List<Object[]> getBestSellingDataList(ResultSet rs) throws SQLException {
        List<Object[]> list = new ArrayList<>();
        while(rs.next()){
            Object[] objects = new Object[5];
            objects[0] = rs.getString(1);
            objects[1] = rs.getString(2);
            objects[2] = rs.getString(3);
            objects[3] = rs.getString(4);
            objects[4] = rs.getInt(5);
            list.add(objects);
        }
        return  list;
    }
    public static List<Object[]> getBestSellingDataList(String sql) throws SQLException {
        ResultSet rs  = DataBaseUtil.produceResultSet(sql);
        List<Object[]> list = new ArrayList<>();
        while(rs.next()){
            Object[] objects = new Object[5];
            objects[0] = rs.getString(1);
            objects[1] = rs.getString(2);
            objects[2] = rs.getString(3);
            objects[3] = rs.getString(4);
            objects[4] = rs.getInt(5);
            list.add(objects);
        }
        return  list;
    }
    public static List<Object[]> getBestSellingDataList(String sql,Object... objects1) throws SQLException {
        ResultSet rs  = DataBaseUtil.prepareResultSet(sql,objects1);
        List<Object[]> list = new ArrayList<>();
        while(rs.next()){
            Object[] objects = new Object[5];
            objects[0] = rs.getString(1);
            objects[1] = rs.getString(2);
            objects[2] = rs.getString(3);
            objects[3] = rs.getString(4);
            objects[4] = rs.getInt(5);
            list.add(objects);
        }
        return  list;
    }
}
